package com.ruoyi.eqmonitor.smdtv.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.eqmonitor.smdtv.domain.Smdtv9;
import com.ruoyi.eqmonitor.smdtv.mapper.SmregisterMapper;
import com.ruoyi.eqmonitor.smdtv.service.ISmdtv9Service;
import com.ruoyi.eqmonitor.smdtv.mapper.Smdtv9Mapper;
import com.ruoyi.eqmonitor.smdtv.vo.AllNameVo;
import com.ruoyi.eqmonitor.smdtv.vo.SumVo;
import com.ruoyi.eqmonitor.utils.Constant;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author YR
 * @description 针对表【smdtv_9】的数据库操作Service实现
 * @createDate 2022-12-06 11:31:57
 */
@Service
public class Smdtv9ServiceImpl extends ServiceImpl<Smdtv9Mapper, Smdtv9>
        implements ISmdtv9Service {

    @Resource
    private Smdtv9Mapper smdtv9Mapper;

    @Resource
    private SmregisterMapper smregisterMapper;

    @Override
    public SumVo getSum(String name) {
        SumVo sumVo = new SumVo();
        Long value = smregisterMapper.getSum(name,smregisterMapper.getTableNameByDatasetName(Constant.Smregister.SMDTV_9.getName()));
        sumVo.setName(Constant.Smregister.SMDTV_9.getName());
        sumVo.setValue(value);
        return sumVo;
    }

    @Override
    public List<Smdtv9> getByName(String name) {
        return smdtv9Mapper.getByName(name,smregisterMapper.getTableNameByDatasetName(Constant.Smregister.SMDTV_9.getName()));
    }

    @Override
    public List<AllNameVo> getAllName() {
        List<AllNameVo> allName = smdtv9Mapper.getAllName(smregisterMapper.getTableNameByDatasetName(Constant.Smregister.SMDTV_9.getName()));
        List<AllNameVo> list = new ArrayList<>();
        Map<String, List<AllNameVo>> collect = allName.stream().collect(Collectors.groupingBy(AllNameVo::getType));
        for (String key : collect.keySet()){
            AllNameVo allNameVo = new AllNameVo();
            allNameVo.setLabel(key);
            List<AllNameVo> list1 = collect.get(key);
            allNameVo.setChildren(list1);
            if (key.equals("一杆式监测站")){
                allNameVo.setValue("1");
            } else if (key.equals("氨氮一体机")){
                allNameVo.setValue("2");
            } else {
                allNameVo.setValue("3");
            }
            list.add(allNameVo);
        }
        return list;
    }

    @Override
    public List<Smdtv9> getByAreaName(String areaName) {
        return smdtv9Mapper.getByAreaName(areaName,smregisterMapper.getTableNameByDatasetName(Constant.Smregister.SMDTV_9.getName()));
    }
}




